package com.yunfei.web;

import com.yunfei.service.ICacheService;
import com.yunfei.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.concurrent.TimeUnit;

@Controller
public class CacheController {

    @Autowired
    private ICacheService cacheService;
    @Autowired
    private RedisService redisService;

    @RequestMapping("/get")
    @ResponseBody
    public Object getCache(@RequestParam String  key) {
        Object obj=redisService.get(key);
        return obj;
    }

    @RequestMapping("/exists")
    @ResponseBody
    public boolean exists(@RequestParam String  key) {
        return  redisService.exists(key);
    }

    @RequestMapping("/set")
    @ResponseBody
    public Object set(@RequestParam String  key,@RequestParam Object  value) {
        return  redisService.set(key,value);
    }
    @RequestMapping("/set2")
    @ResponseBody
    public Object set(@RequestParam String  key,@RequestParam Object  value,@RequestParam long  time,@RequestParam TimeUnit  timeUnit) {
        return  redisService.set(key,value,time,timeUnit);
    }
    @RequestMapping("/set1")
    @ResponseBody
    public Object set(@RequestParam String  key,@RequestParam Object  value,@RequestParam long  time) {
        return  redisService.set(key,value,time);
    }
    @RequestMapping("/getExpireTime")
    @ResponseBody
    public long getExpireTime(@RequestParam String  key) {
        return  redisService.getExpireTime(key);
    }
    @RequestMapping("/remove")
    @ResponseBody
    public boolean remove(@RequestParam String  key) {
        boolean flag=true;
        redisService.remove(key);
        return flag;
    }
}
